<template>
	<view>
		<u-navbar :border-bottom="false" title="收款账号" :title-size="36" :title-bold="true" :title-color="textColor">
		</u-navbar>
		<u-form class="form" :model="form" :rules="formRules" ref="setBankForm">
		<!-- 	<u-form-item label-position="top" label="银行类型" :label-style="labelStyle" prop="mendianname" required right-icon="forward">
				<u-input type="select" :select-open="pickerShow" v-model="form.region" placeholder="请选择银行类型" @click="pickerShow = true" />
			</u-form-item> -->
			
			<u-form-item label-position="top" label="银行账号" :label-style="labelStyle" prop="accountNumber" required>
				<u-input v-model="form.accountNumber" placeholder="请输入银行账号" />
			</u-form-item>
			<u-form-item label-position="top" label="账户名称" :label-style="labelStyle" prop="accountName" required right-icon="forward">
				<u-input v-model="form.accountName" placeholder="请输入账户名称" />
			</u-form-item>
			<u-form-item label-position="top" label="开户银行" :label-style="labelStyle" prop="bankName" required>
				<u-input v-model="form.bankName" placeholder="例:工商银行" />
			</u-form-item>
			<u-form-item label-position="top" label="开户银行全称(含支行)" :label-style="labelStyle" prop="bankOfDeposit" required>
				<u-input v-model="form.bankOfDeposit" placeholder="例:中国工商银行宁波天府路分行" />
			</u-form-item>
		</u-form>
		<set-submit-bt text="保存" @click="handleSubmit" />
	</view>
</template>

<script>
	import SetSubmitBt from '@/components/set-submit-bt/index.vue'
	export default {
		onNavigationBarButtonTap(e) {
			// 弹出modal框
			this.modalShow = true
		},
		components: { SetSubmitBt },
		data() {
			return {
				modalShow: false,
				submitStyle: {
					height: '100rpx',
					color: '#FFFFFF',
					background: this.linearGradient
				},
				labelStyle: {
					fontSize: '30rpx',
					fontWeight: 'bold'
				},
				form: {},
				formRules:{//收款账号表单验证
					accountNumber: [
						{ required: true, message: '请输入银行账号', trigger: 'blur' },
					],
					accountName: [
						{ required: true, message: '请输入账户名称', trigger: 'blur' },
					],
					bankOfDeposit: [
						{ required: true, message: '请输入开户银行全称（含支行）', trigger: 'blur' },
					],
					bankName: [
						{ required: true, message: '请输入开户行', trigger: 'blur' },
					],
				},
				pickerShow: false,
				shopId:'',
			}
		},
		onLoad(options) {
			this.form =JSON.parse(options.data);
			this.shopId = options.id;
		},
		onReady() {
			this.$refs.setBankForm.setRules(this.formRules)
		},
		methods: {
			handleSubmit() {
				// this.$mRouter.push({ route: '/pages/sale/shezhi/yanzheng' })
				uni.showLoading({
					title: 'loading...',
					mask: false
				});
				this.form.shopId = this.shopId;
				this.form.type = this.form.type?this.form.type:'Offline';
				this.$refs.setBankForm.validate(async (valid) => {
					if (!valid){
						uni.hideLoading({
							title: 'loading...',
							mask: false
						});
						return false;
					} 
					const res = await this.$newHttp.post('api/Shop/AddOrUpdateCollection', this.form);
					uni.hideLoading({
						title: 'loading...',
						mask: false
					});
					if (res.code == 200) {
						uni.showToast({
							title: '配置成功',
							duration: 2000
						});
						// this.$mHelper.delayedJump('/pages/mine/index', 'switchTab')
					}else{
						this.$u.toast('配置收款账号失败,错误信息：'+res.erroMessage, 1000)
					}
				})
			}
		}
	}
</script>

<style>
	page {
		background-color: #FFFFFF;
	}
</style>

<style lang="scss" scoped>
	.form {
		padding: 0 70rpx;
	}
</style>
